//package com.allwees.data.dataport.module.base.bo;
//
//import com.allwees.bs.core.model.constant.EPromotionChannel;
//import com.allwees.bs.core.model.payment.enums.EPaymentType;
//import com.allwees.bs.core.model.user.context.UserContext;
//import com.allwees.bs.core.modelbase.constant.EPlatform;
//import com.allwees.core.common.util.DateUtil;
//import com.allwees.core.common.util.http.RequestUtil;
//import lombok.Data;
//import lombok.NoArgsConstructor;
//import lombok.experimental.Accessors;
//import org.apache.commons.lang3.EnumUtils;
//import org.apache.commons.lang3.StringUtils;
//import org.aspectj.lang.ProceedingJoinPoint;
//import org.springframework.data.elasticsearch.annotations.Field;
//import org.springframework.data.elasticsearch.annotations.FieldType;
//import org.springframework.web.context.request.RequestAttributes;
//import org.springframework.web.context.request.RequestContextHolder;
//import org.springframework.web.context.request.ServletRequestAttributes;
//
//import javax.servlet.http.HttpServletRequest;
//import java.math.BigDecimal;
//import java.net.InetAddress;
//import java.util.Date;
//
///**
// *
// *
// * @author yangylsky
// * @since 2020-03-21
// *
// */
//@Data
//@NoArgsConstructor
//@Accessors(chain = true)
//public abstract class BaseLogBo {
//	@Field(store = true)
//    protected Date time = DateUtil.now();
//
//    @Field(store = true, type = FieldType.Keyword, fielddata = true)
//	protected String uid = "";
//
//    @Field(store = true, type = FieldType.Keyword, fielddata = true)
//    protected String userUuid;
//
//    @Field(store = true, type = FieldType.Keyword, fielddata = true)
//    protected String username;
//
//    @Field(store = true, fielddata = true)
//    protected Boolean newUser;
//
//	@Field(store = true, type = FieldType.Keyword, fielddata = true)
//	protected String productUuid;
//
//	@Field(store = true, type = FieldType.Keyword, fielddata = true)
//	protected String productNo;
//
//	@Field(store = true, type = FieldType.Keyword, fielddata = true)
//	protected String productCustomNo;
//
//	@Field(store = true)
//	protected String productName;
//
//	@Field(store = true, type = FieldType.Keyword, fielddata = true)
//	protected String skuUuid;
//
//	@Field(store = true, type = FieldType.Keyword)
//	protected String skuNo;
//
//	@Field(store = true, type = FieldType.Keyword)
//	protected String skuCustomNo;
//
//	@Field(store = true, type = FieldType.Keyword)
//	protected String skuColor;
//
//	@Field(store = true, type = FieldType.Keyword)
//	protected String skuSize;
//
//	@Field(store = true, type = FieldType.Keyword, fielddata = true)
//	protected String retailerUuid;
//
//	@Field(store = true, type = FieldType.Keyword)
//	protected String retailerName;
//
//	@Field(store = true, type = FieldType.Keyword, fielddata = true)
//	protected String storeUuid;
//
//	@Field(store = true, type = FieldType.Keyword, fielddata = true)
//	protected String orderUuid;
//
//	@Field(store = true, type = FieldType.Keyword)
//	protected String orderNo;
//
//	@Field(store = true, type = FieldType.Keyword, fielddata = true)
//	protected String email;
//
//	@Field(store = true, type = FieldType.Keyword, fielddata = true)
//	protected String deviceId;
//
//	@Field(store = true, type = FieldType.Keyword, fielddata = true)
//	protected String typeName;
//
//	@Field(store = true, type = FieldType.Keyword, fielddata = true)
//	protected String msgUuid;
//
//	@Field(store = true, type = FieldType.Keyword, fielddata = true)
//	protected String shareUuid;
//
//	@Field(store = true, type = FieldType.Keyword, fielddata = true)
//	protected String sharerUuid;
//
//	@Field(store = true, type = FieldType.Keyword, fielddata = true)
//	protected EPromotionChannel promotionChannel;
//
//	@Field(store = true, type = FieldType.Keyword, fielddata = true)
//	protected Integer promotionType;
//
//    /**
//     * 展示位置序号
//     */
//    @Field(store = true)
//    protected Integer pos;
//
//	@Field(store = true)
//	protected Integer count;
//
//	@Field(store = true)
//	protected Integer total;
//
//	@Field(store = true)
//	protected Integer current;
//
//	@Field(store = true)
//	protected Integer pageSize;
//
//	@Field(store = true, type = FieldType.Keyword, fielddata = true)
//	protected String key;
//
//	@Field(store = true, type = FieldType.Keyword, fielddata = true)
//	protected String name;
//
//	@Field(store = true)
//    private Integer sum;
//
//	@Field(store = true)
//	protected Integer quantity;
//
//	@Field(store = true)
//	protected BigDecimal amt;
//
//	@Field(store = true)
//	protected BigDecimal amtProduct;
//
//	@Field(store = true)
//	protected BigDecimal amtProductCoupon;
//
//	@Field(store = true)
//	protected BigDecimal amtShipping;
//
//	@Field(store = true)
//	protected BigDecimal amtSku;
//
//	@Field(store = true, type = FieldType.Keyword, fielddata = true)
//    private EPaymentType paymentType;
//
//	/*====================== COMMON =====================*/
//
//	@Field(store = true, type = FieldType.Keyword, fielddata = true)
//	protected EPlatform platform;
//
//    @Field(store = true, type = FieldType.Keyword)
//    protected String url;
//
//    @Field(store = true, type = FieldType.Keyword)
//    protected String referer;
//
//    @Field(store = true, type = FieldType.Keyword)
//    private String userAgent;
//
//    @Field(store = true, type = FieldType.Keyword)
//    private String appVersion;
//
//    @Field(store = true, type = FieldType.Ip, fielddata = true)
//    protected String clientIp;
//
//    @Field(store = true, type = FieldType.Ip, fielddata = true)
//    protected String serverIp;
//
//    @Field(store = true, type = FieldType.Keyword)
//    protected String serverHost;
//
//	/** 经度 */
//	@Field(store = true)
//	private Float lng = 0f;
//
//	/** 维度 */
//	@Field(store = true)
//	private Float lat = 0f;
//
//	/*====================== END OF COMMON =====================*/
//
//    public BaseLogBo setServer(InetAddress inetAddress) {
//        if (inetAddress != null) {
//            this.serverIp = inetAddress.getHostAddress();
//            this.serverHost = inetAddress.getHostName();
//        }
//        return this;
//    }
//
//	public BaseLogBo updateAopInfo(ProceedingJoinPoint pjp) {
//		return updateRequestInfo();
//	}
//
//	public BaseLogBo updateRequestInfo() {
//		RequestAttributes ra = RequestContextHolder.getRequestAttributes();
//		if(ra != null) {
//			HttpServletRequest request = ((ServletRequestAttributes) ra).getRequest();
//			updateRequestInfo(request);
//		}
//
//		return this;
//	}
//
//	public BaseLogBo updateRequestInfo(HttpServletRequest request) {
//		if(StringUtils.isBlank(userUuid)) {
//			setUserUuid(UserContext.getUserUuid());
//		}
//		if(StringUtils.isBlank(username)) {
//			if(UserContext.getUser() != null) {
//				setUsername(UserContext.getUser().getUsername());
//			}
//		}
//		if(StringUtils.isBlank(email)) {
//			if(UserContext.getUser() != null) {
//				String uname = UserContext.getUser().getUsername();
//				if(uname.contains("@")) {
//					setEmail(uname);
//				}
//			}
//		}
//
//		if(StringUtils.isBlank(sharerUuid)) {
//			String srUuid = request.getHeader("sharerUuid");
//			if (StringUtils.isBlank(sharerUuid) && UserContext.getUser() != null) {
//				srUuid = UserContext.getUser().getSharerUuid();
//			}
//			setSharerUuid(srUuid);
//		}
//
//		if(promotionChannel == null) {
//			Integer promotionType = null;
//			EPromotionChannel channel = EnumUtils.getEnum(EPromotionChannel.class, request.getHeader("channel"));
//			if (channel == null && UserContext.getUser() != null) {
//				channel = UserContext.getUser().getInviteChannel();
//				promotionType = 2;
//			} else {
//				promotionType = 1;
//			}
//			if(channel != null){
//				setPromotionType(promotionType);
//				setPromotionChannel(channel);
//			}
//		}
//
//		if(StringUtils.isBlank(uid)) {
//			setUid(request.getHeader("uid"));
//		}
//
//		if(StringUtils.isBlank(url)) {
//			setUrl(RequestUtil.getUrl(request));
//		}
//		if(StringUtils.isBlank(referer)) {
//			setReferer(request.getHeader(RequestUtil.REFERER));
//		}
//		if(platform == null) {
//			setPlatform(EPlatform.parseFrom(request));
//		}
//		if(StringUtils.isBlank(appVersion)) {
//			setAppVersion(request.getHeader(RequestUtil.X_APPVERSION));
//		}
//
//		if(StringUtils.isBlank(clientIp)) {
//			setClientIp(RequestUtil.getIpAddr(request));
//		}
//		if(StringUtils.isBlank(userAgent)) {
//			setUserAgent(request.getHeader(RequestUtil.USER_AGENT));
//		}
//		return setServer(RequestUtil.getSeverAddress());
//	}
//}
